Skip to content

Add optional persistent per-worker HTTP clients - #1

Merged
zekageri merged 5 commits into
mainfrom
feature/persistent-http-client
Jul 19, 2026
Merged

Add optional persistent per-worker HTTP clients#1
zekageri merged 5 commits into
mainfrom
feature/persistent-http-client

Conversation

@zekageri

Copy link
Copy Markdown
Collaborator

Summary

  • add an opt-in LinkConnectionMode::PersistentPerWorker mode while preserving per-request clients as the default
  • retain at most one ESP-IDF HTTP client per worker, with no cross-worker sharing or concurrent handle use
  • reuse clients only for normalized same-origin URLs and replace them for origin changes, idle expiry, request-count limits, poisoned sessions, and shutdown
  • scrub caller headers and POST data after every transfer before queue-owned storage is released
  • keep existing redirect security behavior and never automatically replay failed requests
  • expose request, client lifecycle, eviction, and transport-event diagnostics
  • split the template implementation into focused internal headers

Configuration

LinkConfig config;
config.connectionMode = LinkConnectionMode::PersistentPerWorker;
config.persistentIdleTimeoutMs = 5U * 60U * 1000U;
config.persistentMaxRequestsPerHandle = 0;

Both lifetime limits accept zero as unlimited.

Safety properties

  • one handle is owned by exactly one worker
  • active persistent clients are bounded by maxConcurrentRequests
  • scheme, case-insensitive host, and effective port define the reuse origin
  • cross-origin redirects replace the retained handle and retain the existing header-stripping policy
  • setup, transfer, callback, buffering, or request-scrub failures poison and clean up the retained handle
  • POST, PUT, PATCH, and DELETE requests are not automatically retried
  • worker shutdown cleans retained handles before runtime storage is released

Validation

  • added host tests for defaults, reuse decisions, idle wraparound, default ports, host normalization, IPv6 origins, and invalid ports
  • locally compiled and ran the persistent-client host tests with -Wall -Wextra -pedantic
  • locally syntax-compiled the ESP32 code path against an API-compatible ESP-IDF harness
  • locally passed the embedded source audit for forbidden dynamic STL and exception constructs
  • added a dedicated GitHub Actions workflow for the new host tests

Draft validation remaining

  • run the normal repository CI across supported ESP32 targets
  • perform an on-device long-duration same-origin HTTPS stress test
  • compare internal free heap, largest free block, low-water mark, handle creates/reuses/cleanups, and transport reconnects against PerRequest mode

@zekageri
zekageri marked this pull request as ready for review July 19, 2026 11:51
@zekageri
zekageri merged commit c03c314 into main Jul 19, 2026
28 checks passed
@zekageri
zekageri deleted the feature/persistent-http-client branch July 26, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant